﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FunctionalCLR.Core
{
    public abstract class Node : INode
    {
        public string Value
        {
            get;
            set;
        }

        public abstract object Evaluate();

        public abstract object Accept(IVisitor visitor);

        /// <summary>
        /// Print the tree out in screen
        /// </summary>
        /// <param name="node"></param>
        public void PrintTree()
        {
            Node node;
            Queue<Node> queue = new Queue<Node>();
            queue.Enqueue(this);

            do
            {
                node = queue.Dequeue();
                if (node.GetType().IsSubclassOf(typeof(FuncNode)))
                {
                    FuncNode fn = (FuncNode)node;
                    foreach (Node child in fn.Children)
                    {
                        queue.Enqueue(child);
                    }
                }
                //else if (node.GetType().IsSubclassOf(typeof(OperatorNode)))
                //{
                //    queue.Enqueue(((OperatorNode)node).Left);
                //    queue.Enqueue(((OperatorNode)node).Right);
                //}
            }
            while (queue.Count > 0);
        }
    }
}
